@extends('admin::layouts.master')
@section('content')
    @component('components.tabs',['title' => "角色管理"])
        @slot('nav')
            <li class="nav-item"><a class="active nav-link" href="/admin/role">角色列表</a>
            </li>
            <li class="nav-item"><a class="nav-link" href="#" data-toggle="modal" data-target="#addRole">添加角色</a></li>
            @component('components.modal',['id' => 'addRole','url' => '/admin/role','title' => '角色添加','button' => '添加'])
                <div class="form-group">
                    <label>角色名称</label>
                    <input type="text" placeholder="请输入角色名称" name="title" class="form-control">
                </div>
                <div class="form-group">
                    <label>角色标识</label>
                    <input type="text" placeholder="角色标识需要填写英文" name="name" class="form-control">
                </div>
            @endcomponent
        @endslot
        @slot('body')
            <div class="panel-body">
                <table class="table">
                    <thead>
                    <tr>
                        <th style="width:10%;">编号</th>
                        <th style="width:20%;">角色名称</th>
                        <th class="">角色标识</th>
                        <th class="">添加时间</th>
                        <th class="actions">操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    @foreach($roles as $role)
                        <tr>
                            <td>{{$role['id']}}</td>
                            <td>{{$role['title']}}</td>
                            <td class="">{{$role['name']}}</td>
                            <td class="">{{$role['created_at']}}</td>
                            <td class="actions">
                                <div class="btn-group">
                                    <button type="button" data-toggle="modal" data-target="#editRole{{$role['id']}}"
                                            class="btn btn-default">编辑
                                    </button>
                                    <button type="button" class="btn btn-danger" onclick="delRole(this)">删除</button>
                                    <form action="/admin/role/{{$role['id']}}" method = "post">
                                        @csrf
                                        @method('DELETE')
                                    </form>
                                    <a type="button" href="/admin/role/permission/{{$role['id']}}"
                                       class="btn btn-primary">权限</a>
                                </div>
                                @component('components.modal',['id' => "editRole{$role['id']}",'url' => "/admin/role/{$role['id']}",'title' => "编辑{$role['title']}角色",'button' => '提交' , 'method' =>"PUT"])
                                    <div class="form-group text-left">
                                        <label>角色名称</label>
                                        <input type="text" placeholder="请输入角色名称" name="title" value="{{$role['title']}}"
                                               class="form-control">
                                    </div>
                                    <div class="form-group text-left">
                                        <label>角色标识</label>
                                        <input type="text" placeholder="角色标识需要填写英文" name="name"
                                               value="{{$role['name']}}"
                                               class="form-control">
                                    </div>
                                @endcomponent
                            </td>
                        </tr>
                    @endforeach
                    </tbody>
                </table>
            </div>
        @endslot
    @endcomponent
@endsection
@section('scripts')

    <script>
        function delRole(btn){
            if(confirm('确定要删除角色吗？')){
                $(btn).next('form').trigger('submit')
            }
        }
    </script>

@endsection
